package com.itheima.dao;

import com.itheima.domain.User;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;

import java.util.List;

/**
 * Created by pc on 2021/1/27 22:33
 * Description: day04_eesy_03annotation_mybatis
 */
public interface IUserDao {

    //查询所有用户
    @Select("select * from user")
    @Results(id="userMap",  value = {
            @Result(id = true,column = "id",property = "userId"),
            @Result(column = "username",property = "userName"),
            @Result(column = "sex",property = "userSex"),
            @Result(column = "birthday",property = "userBirthday"),
            @Result(column = "address",property = "userAddress"),
            @Result(column = "id",property = "accounts",
                    many=@Many(select = "com.itheima.dao.IAccountDao.findAccountByUid",fetchType = FetchType.LAZY))
    })
    List<User> findAll();

    @Select("select * from user where id=#{id}")
    //@ResultMap(value = {"userMap"})
    @ResultMap("userMap")
    User findById(Integer id);


    @Select("select * from user where username like #{username}")
    @ResultMap("userMap")
    List<User> findByName(String username);




}
